import Foundation
import Windfish
import DisassemblyRequest

func populateRequestWithGameGlobals(_ request: DisassemblyRequest<LR35902.Address, Gameboy.Cartridge.Location, LR35902.Instruction>) {
  request.addGlobals([
    0x0003: "bool DEBUG_TOOL1",
    0x0004: "bool DEBUG_TOOL2",
    0x0005: "bool DEBUG_TOOL3",
    0xa100: "SAVEFILES",
    0xc100: "decimal wScrollXOffsetForSection",
    0xc105: "decimal wLCDSectionIndex",
    0xc106: "decimal wIntroBGYOffset",
    0xc108: "decimal wNameIndex",
    0xc10b: "MUSIC_TIMING wMusicTrackTiming",
    0xc10e: "bool wNeedsNPCTilesUpdate",
    0xc114: "wNoiseSfxSeaWavesCounter",
    0xc11c: "LINK_MOTION wLinkMotionState",
    0xc11f: "LINK_GROUND_STATUS wLinkGroundStatus",
    0xc121: "bool wUsingSpinAttack",
    0xc122: "decimal wSwordCharge",
    0xc123: "decimal wLinkWalkingFrameCount",
    0xc124: "ROOM_TRANSITION wRoomTransitionState",
    0xc125: "ROOM_TRANSITION_DIRECTION wRoomTransitionDirection",
    0xc126: "wBGUpdateRegionOriginHigh",
    0xc127: "wBGUpdateRegionOriginLow",
    0xc128: "wBGUpdateRegionTilesCount",
    0xc129: "decimal wRoomTransitionFramesBeforeMidScreen",
    0xc12c: "decimal wRoomTransitionTargetScrollX",
    0xc12d: "decimal wRoomTransitionTargetScrollY",
    0xc12e: "wBGOriginHigh",
    0xc12f: "wBGOriginLow",
    0xc133: "wCollisionType",
    0xc136: "SWORD_DIRECTION wSwordDirection",
    0xc137: "SWORD_ANIMATION_STATE wSwordAnimationState",
    0xc13d: "wRandomSeed",
    0xc143: "bool wIsLinkInTheAir",
    0xc14a: "bool wIsRunningWithPegasusBoots",
    0xc14b: "decimal wPegasusBootsChargeMeter",
    0xc14c: "bool wIsShootingArrow",
    0xc14d: "decimal wProjectileCount",
    0xc14e: "bool wHasPlacedBomb",
    0xc14f: "bool wInventoryAppearing",
    0xc155: "decimal wScreenShakeHorizontal",
    0xc156: "decimal wScreenShakeVertical",
    0xc159: "decimal wInventoryCursorFrameCounter",
    0xc15a: "bool wHasMirrorShield",
    0xc15b: "bool wIsUsingShield",
    0xC166: "wLinkPlayingOcarinaCountdown",
    0xC169: "wNextJingle",
    0xC16B: "wTransitionSequenceCounter",
    0xC16F: "wDialogOpenCloseAnimationFrame",
    0xC170: "wDialogCharacterIndex",
    0xC171: "wDialogNextCharPosition",
    0xC172: "wDialogScrollDelay",
    0xC173: "wDialogIndex",
    0xC17B: "wFreeMovementMode",
    0xC17F: "wTransitionGfx",
    0xC180: "wTransitionGfxFrameCount",
    0xC19F: "wDialogState",
    0xC1A5: "wConveyorBeltsCount",
    0xC1A9: "wDialogGotItem",
    0xC1AA: "wDialogGotItemCountdown",
    0xC1BC: "wLoadPreviousMapCountdown",
    0xC1C0: "wBombArrowCooldown",
    0xC200: "wEntitiesPosXTable",
    0xC201: "wEntity1PosX",
    0xC202: "wEntity2PosX",
    0xC203: "wEntity3PosX",
    0xC204: "wEntity4PosX",
    0xC205: "wEntity5PosX",
    0xC206: "wEntity6PosX",
    0xC207: "wEntity7PosX",
    0xC208: "wEntity8PosX",
    0xC209: "wEntity9PosX",
    0xC20A: "wEntityAPosX",
    0xC20B: "wEntityBPosX",
    0xC20C: "wEntityCPosX",
    0xC20D: "wEntityDPosX",
    0xC20E: "wEntityEPosX",
    0xC20F: "wEntityFPosX",
    0xC210: "wEntitiesPosYTable",
    0xC211: "wEntity1PosY",
    0xC212: "wEntity2PosY",
    0xC213: "wEntity3PosY",
    0xC214: "wEntity4PosY",
    0xC215: "wEntity5PosY",
    0xC216: "wEntity6PosY",
    0xC217: "wEntity7PosY",
    0xC218: "wEntity8PosY",
    0xC219: "wEntity9PosY",
    0xC21A: "wEntityAPosY",
    0xC21B: "wEntityBPosY",
    0xC21C: "wEntityCPosY",
    0xC21D: "wEntityDPosY",
    0xC21E: "wEntityEPosY",
    0xC21F: "wEntityFPosY",
    0xC220: "wEntitiesPosXSignTable",
    0xC230: "wEntitiesPosYSignTable",
    0xC240: "wEntitiesSpeedXTable",
    0xC241: "wEntity1SpeedX",
    0xC242: "wEntity2SpeedX",
    0xC243: "wEntity3SpeedX",
    0xC244: "wEntity4SpeedX",
    0xC245: "wEntity5SpeedX",
    0xC246: "wEntity6SpeedX",
    0xC247: "wEntity7SpeedX",
    0xC248: "wEntity8SpeedX",
    0xC249: "wEntity9SpeedX",
    0xC24A: "wEntityASpeedX",
    0xC24B: "wEntityBSpeedX",
    0xC24C: "wEntityCSpeedX",
    0xC24D: "wEntityDSpeedX",
    0xC24E: "wEntityESpeedX",
    0xC24F: "wEntityFSpeedX",
    0xC250: "wEntitiesSpeedYTable",
    0xC251: "wEntity1SpeedY",
    0xC252: "wEntity2SpeedY",
    0xC253: "wEntity3SpeedY",
    0xC254: "wEntity4SpeedY",
    0xC255: "wEntity5SpeedY",
    0xC256: "wEntity6SpeedY",
    0xC257: "wEntity7SpeedY",
    0xC258: "wEntity8SpeedY",
    0xC259: "wEntity9SpeedY",
    0xC25A: "wEntityASpeedY",
    0xC25B: "wEntityBSpeedY",
    0xC25C: "wEntityCSpeedY",
    0xC25D: "wEntityDSpeedY",
    0xC25E: "wEntityESpeedY",
    0xC25F: "wEntityFSpeedY",
    0xC290: "wEntitiesWalkingTable",
    0xC2A0: "wEntitiesCollisionsTable",
    0xC2B0: "wEntitiesUnknownTableB",
    0xC2C0: "wEntitiesUnknownTableC",
    0xC2D0: "wEntitiesUnknownTableD",
    0xC2E0: "wEntitiesTransitionCountdownTable",
    0xC2F0: "wEntitiesUnknowTableF",
    0xC300: "wEntitiesUnknowTableG",
    0xC310: "wEntitiesPosZTable",
    0xC320: "wEntitiesSpeedZTable",
    0xC360: "wEntitiesHealthTable",
    0xC3A0: "wEntitiesTypeTable",
    0xC3B0: "wEntitiesUnknownTableG",
    0xC3CB: "wObjectAffectingBGPalette",
    0xC3CC: "wBGPaletteEffectAddress",
    0xC458: "wDroppedItemsCountdown",
    0xC460: "wEntitiesLoadOrderTable",
    0xC5A7: "wBossAgonySFXCountdown",
    0xC5AA: "wEggMazeProgress",
    0xC5AB: "wDialogSFX",
    0xC5AF: "wNextWorldMusicTrackCountdown",
    0xD000: "wIsFileSelectionArrowShifted",
    0xD001: "wIntroTimer",
    0xD002: "wIntroSubTimer",
    0xD360: "wActiveJingle",
    0xD368: "wActiveMusicTrack",
    0xD370: "wActiveWaveSfx",
    0xD378: "wActiveNoiseSfx",
    0xD401: "wWarp0MapCategory",
    0xD402: "wWarp0Map",
    0xD403: "wWarp0Room",
    0xD404: "wWarp0DestinationX",
    0xD405: "wWarp0DestinationY",
    0xD406: "wWarp1MapCategory",
    0xD407: "wWarp1Map",
    0xD408: "wWarp1Room",
    0xD409: "wWarp1DestinationX",
    0xD40A: "wWarp1DestinationY",
    0xD40B: "wWarp2MapCategory",
    0xD40C: "wWarp2Map",
    0xD40D: "wWarp2Room",
    0xD40E: "wWarp2DestinationX",
    0xD40F: "wWarp2DestinationY",
    0xD410: "wWarp3MapCategory",
    0xD411: "wWarp3Map",
    0xD412: "wWarp3Room",
    0xD413: "wWarp3DestinationX",
    0xD414: "wWarp3DestinationY",
    0xD415: "wPieceOfPowerKillCount",
    0xD416: "wWarp0PositionTileIndex",
    0xD417: "wWarp1PositionTileIndex",
    0xD418: "wWarp2PositionTileIndex",
    0xD419: "wWarp3PositionTileIndex",
    0xD462: "wCompassSfxCountdown",
    0xD47A: "wPowerUpHits",
    0xD47B: "wForceFileSelectionScreenMusic",
    0xD47C: "wActivePowerUp",
    0xD47E: "wDidStealItem",
    0xD480: "wDungeonMinimap",
    0xD600: "wRequests",
    0xD601: "wRequestDestinationHigh",
    0xD602: "wRequestDestinationLow",
    0xD603: "wRequestLength",
    0xD604: "wRequestData",
    0xD6FA: "wRoomSwitchableObject",
    0xD700: "wRoomObjectsArea",
    0xD711: "wRoomObjects",
    0xD800: "wOverworldRoomStatus",
    0xD900: "wIndoorARoomStatus",
    0xDA00: "wIndoorBRoomStatus",
    0xDB00: "wAButtonSlot",
    0xDB01: "wBButtonSlot",
    0xDB02: "wInventoryItem1",
    0xDB03: "wInventoryItem2",
    0xDB04: "wInventoryItem3",
    0xDB05: "wInventoryItem4",
    0xDB06: "wInventoryItem5",
    0xDB07: "wInventoryItem6",
    0xDB08: "wInventoryItem7",
    0xDB09: "wInventoryItem8",
    0xDB0A: "wInventoryItem9",
    0xDB0B: "wInventoryItem10",
    0xDB0C: "wHasFlippers",
    0xDB0D: "wHasMedicine",
    0xDB0E: "wTradeSequenceItem",
    0xDB0F: "wSeashellsCount",
    0xDB11: "wHasTailKey",
    0xDB12: "wHasAnglerKey",
    0xDB13: "wHasFaceKey",
    0xDB14: "wHasBirdKey",
    0xDB15: "wGoldenLeavesCount",
    0xDB16: "wDungeonItemFlags",
    0xDB43: "wPowerBraceletLevel",
    0xDB44: "wShieldLevel",
    0xDB45: "wArrowCount",
    0xDB4C: "wMagicPowderCount",
    0xDB4D: "wBombCount",
    0xDB4E: "wSwordLevel",
    0xDB4F: "wName",
    0xDB56: "wIsBowWowFollowingLink",
    0xDB57: "wDeathCount",
    0xDB5A: "wHealth",
    0xDB5B: "wMaxHealth",
    0xDB5C: "wHeartPiecesCount",
    0xDB5D: "wRupeeCountHigh",
    0xDB5E: "wRupeeCountLow",
    0xDB5F: "wSpawnLocationData",
    0xDB60: "wSpawnMapId",
    0xDB61: "wSpawnMapRoom",
    0xDB62: "wSpawnPositionX",
    0xDB63: "wSpawnPositionY",
    0xDB64: "wSpawnIndoorRoom",
    0xDB65: "wHasInstrument1",
    0xDB66: "wHasInstrument2",
    0xDB67: "wHasInstrument3",
    0xDB68: "wHasInstrument4",
    0xDB69: "wHasInstrument5",
    0xDB6A: "wHasInstrument6",
    0xDB6B: "wHasInstrument7",
    0xDB6C: "wHasInstrument8",
    0xDB6E: "wIsThief",
    0xDB73: "wIsMarinFollowingLink",
    0xDB76: "wMaxMagicPowder",
    0xDB77: "wMaxBombs",
    0xDB78: "wMaxArrows",
    0xDB79: "wIsGhostFollowingLink",
    0xDB7A: "wDB7A",
    0xDB7B: "wIsRoosterFollowingLink",
    0xDB90: "wAddRupeeBufferHigh",
    0xDB91: "wAddRupeeBufferLow",
    0xDB92: "wSubstractRupeeBufferHigh",
    0xDB93: "wSubstractRupeeBufferLow",
    0xDB94: "wDB94",
    0xDB97: "wBGPalette",
    0xDB98: "wOBJ0Palette",
    0xDB99: "wOBJ1Palette",
    0xDB9A: "wWindowY",
    0xDB9C: "wMapEntranceRoom",
    0xDB9D: "wMapEntrancePositionX",
    0xDB9E: "wMapEntrancePositionY",
    0xDBA5: "wIsIndoor",
    0xDBA6: "wSaveSlot",
    0xDBA7: "wSaveFilesCount",
    0xDBAE: "wIndoorRoom",
    0xDBB0: "wMinimapLayout",
    0xDBB1: "wLinkMapEntryPositionX",
    0xDBB2: "wLinkMapEntryPositionY",
    0xDBB5: "wKillCount2",
    0xDBC9: "wTorchesCount",
    0xDBCC: "wHasDungeonMap",
    0xDBCD: "wHasDungeonCompass",
    0xDBCE: "wHasDungeonStoneSlab",
    0xDBCF: "wHasDungeonBossKey",
    0xDBD0: "wSmallKeysCount",
    0xDC00: "wFile1DeathCountHigh",
    0xDC01: "wFile1DeathCountLow",
    0xDC02: "wFile2DeathCountHigh",
    0xDC03: "wFile2DeathCountLow",
    0xDC04: "wFile3DeathCountHigh",
    0xDC05: "wFile3DeathCountLow",
    0xDC0C: "wPhotos1",
    0xDC0D: "wPhotos2",
    0xDC0F: "wTunicType",
    0xDDD1: "wPaletteUnknownA",
    0xDDD2: "wPaletteToLoadForTileMap",
    0xDDD3: "wPaletteUnknownC",
    0xDDD4: "wPaletteUnknownD",
    0xDDD5: "wPaletteUnknownE",
    0xDDE0: "wColorDungeonRoomStatus",
    0xc1bf: "decimal wScrollXOffset",
    0xc280: "ENTITY_STATE wEntitiesStateTable",
    0xc500: "bool wAlternateBackgroundEnabled",
    0xd369: "wAudioData",
    0xd379: "wAudioSelection",
    0xd46c: "bool wBossDefeated",
    0xd6fc: "bool wEnginePaused",
    0xd6fd: "LCDCF wLCDControl",
    0xd6fe: "wTileMapToLoad",
    0xd6ff: "wBGMapToLoad",
    0xdb95: "GAMEMODE wGameMode",
    0xdb96: "wGameSubMode",
    0xdbaf: "wCurrentBank",
    0xff80: "hRomBank",
    0xff81: "hTemp",
    0xff82: "hCodeTemp",
    0xff90: "bool hNeedsBGTilesUpdate",
    0xff91: "bool hNeedsEnemyTilesUpdate",
    0xff96: "decimal hBaseScrollX",
    0xff97: "decimal hBaseScrollY",
    0xff98: "decimal hLinkX",
    0xff99: "decimal hLinkY",
    0xff9a: "decimal hLinkXDelta",
    0xff9b: "decimal hLinkYDelta",
    0xff9d: "hLinkAnimationState",
    0xff9e: "DIRECTION hLinkDirection",
    0xff9f: "decimal hLinkXFinal",
    0xffa0: "decimal hLinkYFinal",
    0xffa4: "ANIMATED_TILES hAnimatedTilesGroup",
    0xffa6: "decimal hAnimatedTilesFrameCount",
    0xffa7: "hAnimatedTilesDataOffset",
    0xffa9: "hWindowY",
    0xffaa: "hWindowX",
    0xffb0: "TRACK hMusicTrack",
    0xffb1: "TRACK hNextMusicTrack",
    0xffb5: "decimal hButtonsInactiveDelay",
    0xffbf: "TRACK hNextWorldMusicTrack",
    0xffc0: "hDMARoutine",
    0xffcb: "BUTTON hPreviousJoypadState",
    0xffcc: "BUTTON hJoypadState",
    0xffcd: "decimal hSwordIntersectedAreaY",
    0xffce: "decimal hSwordIntersectedAreaX",
    0xffd1: "hNeedsRenderingFrame",
    0xffd7: "hScratchA",
    0xffd8: "hScratchB",
    0xffd9: "hScratchC",
    0xffda: "hScratchD",
    0xffdf: "hRoomPaletteBank",
    0xffe0: "hScratchE",
    0xffe1: "hScratchF",
    0xffe2: "hScratchG",
    0xffe3: "hScratchH",
    0xffe4: "hScratchI",
    0xffe5: "hScratchJ",
    0xffe6: "hFreeWarpDataAddress",
    0xffe7: "hFrameCounter",
    0xffe8: "hScratchK",
    0xffe9: "hScratchL",
    0xffea: "hActiveEntityState",
    0xffeb: "ENTITY hActiveEntityType",
    0xffec: "decimal wActiveEntityPosY",
    0xffee: "decimal wActiveEntityPosX",
    0xfff0: "bool hActiveEntityWalking",
    0xfff2: "JINGLE hJingle",
    0xfff3: "WAVE hWaveSfx",
    0xfff4: "NOISE hNoiseSfx",
    0xfff6: "hMapRoom",
    0xfff7: "hMapID",
    0xfff8: "ROOM_STATUS hRoomStatus",
    0xfff9: "SCROLL_VIEW hIsSideScrolling",
    0xfffa: "decimal hLinkRoomPosition",
    0xfffb: "decimal hLinkFinalRoomPosition",
    0xfffd: "bool hDidRenderFrame",
  ])

  (LR35902.Address(0xc281)...LR35902.Address(0xC28F)).forEach {
    request.addGlobal(at: $0, named: "ENTITY_STATE wEntity\(UInt8($0 - 0xc280).hexString)State")
  }
}
